public class ThreadDemo10 {

    public static void main(String[] args) {
        Thread t = new Thread(() -> {
            //currentThread获取当前线程实例 此处currentThread获取的对象是t
            //那个线程调用该方法，返回的就是该线程的对象
            //isInterrupted就是t对象自带的一个标志位
           while (!Thread.currentThread().isInterrupted()) {
               System.out.println("hello t");
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   e.printStackTrace();
                   break;
               }
           }
        });

        t.start();

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //将t内部的标志位给设置为true
        t.interrupt();

    }
}
